#    Copyright 2008, 2009 Tri-County Electric Cooperative, St. Matthews, South Carolina
#    This file is part of COOPGIS.
#    COOPGIS is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    COOPGIS is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with COOPGIS.  If not, see <http://www.gnu.org/licenses/>.
#************************BEGIN Add Include Files to Path************************
import sys
NeededPaths=['/opt/coopgis/djangoproject/include', '/opt/coopgis/djangoproject']
for path in NeededPaths:
    if(not path in sys.path):
        sys.path.append(path)
#************************END   Add Include Files to Path************************
import application, cis, command, geography, oms, staker, symbology, unsorted
import COOPGIS_Ajax, COOPGIS_GPS, COOPGIS_Misc, COOPGIS_ReportLab, COOPGIS_String, COOPGIS_Update
import os, csv, shutil, datetime, time, reportlab, djangoproject.settings
from django.contrib.gis.db import models
from django.contrib.gis.geos import *
from django.http import HttpResponse
from django.contrib import admin
import _mysql as mysql
from django.contrib.auth.models import User


class AMRDBCache():
    def __init__(self):
        self.RawData={} #Dict[str(serialnumber) + ":  " + str(metertccurdatetime)[:10]], for any day requested, get all records for that day
        self.MeteracctstcDateTimeDates=[]  #Dates that have been cached  for Meteracctstc

    def GetRawDataBySerialNumberByDateTime(self, SerialNumber, DateTime):
        #import AMR
        Key=str(SerialNumber) + ':  ' + str(DateTime)[:10]
        if(not DateTime in self.MeteracctstcDateTimeDates):
            self.AmrtotaldataDateTimeDates.append(DateTime)
            NewTotalData=list(AMR.Meteracctstc.objects.filter(metertccurdatetime=DateTime))
            for i in NewTotalData:
                self.AmrtotaldataDateTime[str(i.serialnumber) + ':  ' + str(i.metertccurdatetime)[:10]] = i
        try:
            return self.AmrtotaldataDateTime[Key]
        except:
            return None

  
